﻿/// <reference path="jquery-1.10.1.min.js" />

$(document).ready(function () {
    var app = {};
    app['userName'] = $('#userName');
    app['password'] = $('#password');
    app['companyid'] = $("#company");
    app['btn'] = $('.btn');
    app['msg'] = $('#msg');
    app.btn.click(function (e) {

        if (app.userName.val().length === 0) {//验证用户名不能为空
            //alert('hello world');
            app.msg.text('用户名不能为空！').show().fadeOut(1000);
            e.preventDefault();
        } else if (app.password.val().length === 0) {//验证密码不能空
            app.msg.text('密码不能为空！').show().fadeOut(1000);
            e.preventDefault();
        } else { //去服务端去验证用户名和密码是否正确
            e.preventDefault();
            $.ajax({
                type: 'POST',
                url: 'WebHandler.ashx?type=logon&rnd=' + Math.random(),
                data: { userName: app.userName.val(), password: app.password.val(), companyid: app.companyid.val() },
                //dataType: 'json',
                beforeSend: function (xhr) {
                    app.msg.text('正在验证...').fadeIn(1000);
                },
                success: function (data) {
                    if (data === 'ok') {
                        app.msg.text('').fadeOut(1000);
                        //$.cookie('name', null);
                        //$.cookie('name', $.md5(app.userName.val(), null, true));
                        location.href = 'showsales.aspx';
                    } else {
                        app.msg.text(data).fadeIn(1000);
                    }
                }
            });
        }
    });
});
